local guibi_viewas = fk.CreateSkill{
  name = "#hanqing__guibi_viewas",
}

Fk:loadTranslationTable{
  ["#hanqing__guibi_viewas"] = "归璧",
}

guibi_viewas:addEffect("viewas", {
  expand_pile = function (self, player)
    return table.filter(self.cardIds, function (id)
      return not table.contains(player:getCardIds("h"), id)
    end)
  end,
  card_filter = function (self, player, to_select, selected)
    if #selected == 0 and table.contains(self.cardIds, to_select) then
      local card = Fk:getCardById(to_select)
      if table.contains(player:getCardIds("e"), to_select) then
        card = Fk:getCardById(to_select, true)
      end
      return player:canUse(card, { bypass_distances = true, bypass_times = true })
    end
  end,
  view_as = function(self, player, cards)
    if #cards == 1 then
      if table.contains(player:getCardIds("e"), cards[1]) then
        return Fk:getCardById(cards[1], true)
      else
        return Fk:getCardById(cards[1])
      end
    end
    return nil
  end,
})

guibi_viewas:addAI(nil, "vs_skill")

return guibi_viewas
